package actions;

import bin.Mud;
import exceptions.MudExceptions;

public class HelpDecider {
    private Mud mudWindow;
    private Helpers currentHelper;

    public enum Helpers {
        HELP,
        DIRECTIONS
    }

    public HelpDecider(Mud mudWindow) {
        this.mudWindow = mudWindow;
    }

    public boolean isHelp() {
        String help = mudWindow.getCommand();
        return (help.startsWith("HELP"));
    }

    public Helpers getHelp() {
        String help = mudWindow.getCommand();
        if (help.equals("HELP DIRECTIONS")) {
            currentHelper = Helpers.DIRECTIONS;
        } else if (help.equals("HELP")) {
            currentHelper = Helpers.HELP;
        }
        return currentHelper;
    }

    public void showHelp() {
        if (getHelp() == Helpers.DIRECTIONS) {
            mudWindow.setReturnText("There are 6 directions to travel.  North, East, South, West, Up, and Down.  You can type" +
                    " the direction or just the first letter of the direction to move.");
        } else if (getHelp() == Helpers.HELP) {
            mudWindow.setReturnText("Available Help Sections:" + getHelpersString());
        } else {
            throw MudExceptions.invalidHelp();
        }
    }

    private String getHelpersString() {
        StringBuffer buf = new StringBuffer();
        String rtn;
        for (Helpers c : Helpers.values()) {
            buf.append("\n");
            buf.append(c);
        }
        rtn = buf.toString();
        return rtn;
    }
}